<?php

namespace app\modules\index\services;

use app\common\services\BaseService;
use app\models\Merchant;

class MerchantService extends BaseService{

    private const SELECT = ['merchant_id','merchant_name','merchant_desc','announce','thumbnail','customer_type','lng_lat','business_time','delivery_type','delivery_rule'];

    /**
     * 获取信息
     * @param $id
     * @return array|\yii\db\ActiveRecord|null
     */
    public static function getInfoById($id){
        $data = Merchant::find()
            ->asArray(true)
            ->select(self::SELECT)
            ->where(['merchant_id'=>$id])
            ->andWhere(['is_show'=>2])
            ->one();
        //设置营业标记
        $range = explode("-",$data['business_time']);
        $data['business_status'] =  date("H") >= $range[0] && date("H") <= $range[1] ? 2 : 1;
        return $data;
    }
}